<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/**
 * Controller to for user related information
 * 
 * Sample bench Marking
 *    $this->benchmark->mark('login_start'); 
 *    $this->benchmark->mark('login_end'); 
 *    $this->benchmark->elapsed_time('login_start', 'login_end');
 */
class Price_range extends MY_Controller{

    public function __construct() {
        parent::__construct();
        //$this->acl_auth->restrict_access('admin');
        $this->load->model('price_range_model');
    }
    
    /**
     * 
     */
	public function index()
	{
        $views['_header'] = 'user/header';
        $views['_content'] = 'user/price_range';
        

        $data['price_range']= $this->price_range_model->getall();
        $data['title']='Price Range';
        $data['action'] = 'list';

        //var_dump($data['price_range']);
        
        
        $this->template->load('user/main', $views, $data);
	}
    
    /**
     * 
     * List the users except admin permission
     */
    public function edit($id="")
    {
        $this->enableProfiler();
        
        $views['_header'] = 'user/header';
        $views['_content'] = 'user/price_range';
        

        $data['title']='Price Range';
        $data['action'] = 'edit';
        if (isset($id) && $id){
            $data['id'] = base64_decode (urldecode($id));
            $data['data'] = $this->price_range_model->get($data['id']);
        }
        
        $this->template->load('user/main', $views, $data);
        
    }

    /**
     * Delete user
     * 
     * @param type $id
     */
    public function delete($id=""){
        
        if (isset($id) && $id){
            $id = base64_decode(urldecode($id));
        }
        try{            
            if ((int)$id > 0){
                $this->price_range_model->delete($id);
            
                $this->session->set_flashdata('success', 'One item sucessfully deleted');
            }
        }  catch (Exception $e){
            $this->session->set_flashdata('error', $e->getMessage());
        }
        redirect('price_range');        
    }
    
    /**
     * register
     */
    public function save()
    {
//        var_dump($this->input->post());
//        exit();
        //$this->acl_auth->restrict_access('admin');
        //$this->enableProfiler();
        
        if($this->isPost())
        {
            $data = $this->input->post();
            
            $success = $this->price_range_model->save($data);
            if ($success){
                $this->session->set_flashdata('success', 'Price range successfully save.');
            }else{
                $this->session->set_flashdata('error', 'Price range failed to add.');
            }
            redirect('price_range');
                
        }
    }
    
} // User class
